import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';

import { getRangePickerDefaultProps } from '#/utils';

import { $t } from '#/locales';

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'name',
      label: $t('views.bpm.task.common.processName'),
      component: 'Input',
      componentProps: {
        placeholder: $t('views.bpm.task.common.processNamePlaceholder'),
        allowClear: true,
      },
    },
    {
      fieldName: 'createTime',
      label: $t('views.bpm.task.copy.createTime'),
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
  return [
    {
      field: 'processInstanceName',
      title: $t('views.bpm.task.common.processName'),
      minWidth: 200,
      fixed: 'left',
    },
    {
      field: 'summary',
      title: $t('views.bpm.task.common.summary'),
      minWidth: 200,
      formatter: ({ cellValue }) => {
        return cellValue && cellValue.length > 0
          ? cellValue
              .map((item: any) => `${item.key} : ${item.value}`)
              .join('\n')
          : '-';
      },
    },
    {
      field: 'startUser.nickname',
      title: $t('views.bpm.task.common.startUser'),
      minWidth: 120,
    },
    {
      field: 'processInstanceStartTime',
      title: $t('views.bpm.task.common.processStartTime'),
      minWidth: 180,
      formatter: 'formatDateTime',
    },
    {
      field: 'activityName',
      title: $t('views.bpm.task.copy.activityName'),
      minWidth: 180,
    },
    {
      field: 'createUser.nickname',
      title: $t('views.bpm.task.copy.creator'),
      minWidth: 180,
      formatter: ({ cellValue }) => {
        return cellValue || '-';
      },
    },
    {
      field: 'reason',
      title: $t('views.bpm.task.copy.reason'),
      minWidth: 180,
    },
    {
      field: 'createTime',
      title: $t('views.bpm.task.copy.createTime'),
      minWidth: 180,
      formatter: 'formatDateTime',
    },
    {
      title: $t('common.action'),
      width: 120,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
